package com.tzeng.qr_codescan;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
	public static final int SCAN_RESULT_REQUEST = 10000;
	Button button1;
	TextView result;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		result = (TextView) this.findViewById(R.id.result);
		button1 = (Button) this.findViewById(R.id.button1);
		button1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this,
						com.beclub.zxing.MipcaActivityCapture.class);
				MainActivity.this.startActivityForResult(intent,
						SCAN_RESULT_REQUEST);
			}
		});
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		if (resultCode == -1) {
			// Scan result is available by making a call to
			// data.getStringExtra(ZBarConstants.SCAN_RESULT)
			// Type of the scan result is available by making a call to
			// data.getStringExtra(ZBarConstants.SCAN_RESULT_TYPE)
			// 扫码成功回调 参数1.scan_result扫码的内容 2.扫码的类型
			button1.setText("继续扫码");
			result.setText("二维码的内容："
					+ data.getStringExtra(com.beclub.zxing.ZxingConstants.SCAN_RESULT));
			Toast.makeText(
					this,
					"二维码的内容："
							+ data.getStringExtra(com.beclub.zxing.ZxingConstants.SCAN_RESULT),
					3 * 1000).show();
			// The value of type indicates one of the symbols listed in Advanced
			// Options below.
		} else if (resultCode == 0) {
			result.setText("扫码失败");
			// 扫码失败回调
			Toast.makeText(this, "扫码失败", 1 * 1000).show();
		}
		super.onActivityResult(requestCode, resultCode, data);
	}
}
